package com.brucekong.slm.controller.console;

import com.brucekong.slm.common.PageResult;
import com.brucekong.slm.model.console.TopCardDomain;
import com.brucekong.slm.model.console.TopSearchDomain;
import com.brucekong.slm.service.console.TopService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 控制台控制类
 */
@RestController
@RequestMapping("/console")
@Slf4j
@Api(value = "控制台模块", tags = "控制台模块")
public class TopController {

    private PageResult pageResult = new PageResult();

    @Autowired
    private TopService topService;

    /**
     * 今日热搜
     *
     * @return pageResult 获取今日热搜列表
     */
    @GetMapping("/topSearch")
    @SuppressWarnings("unchecked")
    @ApiOperation(value = "今日热搜", notes = "获取今日热搜列表", code = 200, produces = "application/json", responseContainer = "List", response = PageResult.class)
    public PageResult getTopSearch(@RequestParam(name = "page", required = false, defaultValue = "1") int page,
                                   @RequestParam(name = "limit", required = false, defaultValue = "10") int limit) {
        log.info("/console/topSearch");
        PageInfo<TopSearchDomain> topSearchDomainPageInfo = topService.getTopSearch(page, limit);

        pageResult.setCode(0);
        pageResult.setMsg(null);
        pageResult.setSuccess(true);
        pageResult.setCount(topSearchDomainPageInfo.getTotal());
        pageResult.setData(topSearchDomainPageInfo.getList());
        return pageResult;
    }

    /**
     * 今日热搜
     *
     * @return pageResult 获取今日热搜列表
     */
    @GetMapping("/topCard")
    @SuppressWarnings("unchecked")
    @ApiOperation(value = "今日热帖", notes = "获取今日热帖搜列表", code = 200, produces = "application/json", responseContainer = "List", response = PageResult.class)
    public PageResult getTopCard(@RequestParam(name = "page", required = false, defaultValue = "1") int page,
                                 @RequestParam(name = "limit", required = false, defaultValue = "10") int limit) {
        log.info("/console/topCard");
        PageInfo<TopCardDomain> topCardDomainPageInfo = topService.getTopCard(page, limit);

        pageResult.setCode(0);
        pageResult.setMsg(null);
        pageResult.setSuccess(true);
        pageResult.setCount(topCardDomainPageInfo.getTotal());
        pageResult.setData(topCardDomainPageInfo.getList());
        return pageResult;
    }

}